package com.assessment.servermanager.service.impl;

import java.util.Arrays;
import java.util.Date;
import java.util.stream.Collectors;

import cn.hutool.core.util.ObjectUtil;
import com.assessment.servermanager.commen.entity.PageQuery;
import com.assessment.servermanager.commen.page.TableDataInfo;
import com.assessment.servermanager.commen.utils.StringUtils;
import com.assessment.servermanager.entity.TbEmployee;
import com.assessment.servermanager.entity.bo.TbEmployeeBo;
import com.assessment.servermanager.entity.vo.TbEmployeeVo;
import com.assessment.servermanager.mapper.TbEmployeeMapper;
import com.assessment.servermanager.service.ITbEmployeeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author jiajia
 * @date 2023-08-28
 */
@Service
public class TbEmployeeServiceImpl implements ITbEmployeeService {
    @Autowired
    private TbEmployeeMapper tbEmployeeMapper;

    /**
     * 查询【请填写功能名称】
     *
     * @param id 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public TbEmployee selectTbEmployeeById(Long id) {
        return tbEmployeeMapper.selectById(id);
    }


    /**
     * 查询【请填写功能名称】列表
     *
     * @param tbEmployeeBo 【请填写功能名称】
     * @return 【请填写功能名称】
     */@Override
    public TableDataInfo<TbEmployeeVo> selectTbEmployeeList(TbEmployeeBo tbEmployeeBo, PageQuery pageQuery) {
        QueryWrapper<TbEmployee> queryWrapper = new QueryWrapper<TbEmployee>();
        queryWrapper.eq(StringUtils.isNotEmpty(tbEmployeeBo.getAddress()),"emp.address", tbEmployeeBo.getAddress());
        queryWrapper.eq(StringUtils.isNotEmpty(tbEmployeeBo.getCardId()),"emp.cardId", tbEmployeeBo.getCardId());
        queryWrapper.apply(ObjectUtil.isNotNull(tbEmployeeBo.getCreateDate()),"emp.createDate between"+ tbEmployeeBo.getStartTime() +" and "+ tbEmployeeBo.getEndTime());
        queryWrapper.eq(StringUtils.isNotEmpty(tbEmployeeBo.getEmail()),"emp.email", tbEmployeeBo.getEmail());
        queryWrapper.eq(tbEmployeeBo.getGender() != null,"emp.gender", tbEmployeeBo.getGender());
        queryWrapper.like(StringUtils.isNotEmpty(tbEmployeeBo.getName()),"emp.name", tbEmployeeBo.getName());
        queryWrapper.eq(StringUtils.isNotEmpty(tbEmployeeBo.getPhone()),"emp.phone", tbEmployeeBo.getPhone());
        queryWrapper.eq(StringUtils.isNotEmpty(tbEmployeeBo.getPostCode()),"emp.postCode", tbEmployeeBo.getPostCode());
        queryWrapper.eq(tbEmployeeBo.getDid() != null,"emp.did", tbEmployeeBo.getDid());
        queryWrapper.eq(StringUtils.isNotEmpty(tbEmployeeBo.getJobName()),"emp.jobName", tbEmployeeBo.getJobName());
        queryWrapper.eq(tbEmployeeBo.getUid() != null,"emp.uid", tbEmployeeBo.getUid());
        queryWrapper.eq("emp.delFlag",0);
        Page<TbEmployeeVo> page = tbEmployeeMapper.selectPageUserList(pageQuery.build(), queryWrapper);
        return TableDataInfo.build(page);
    }

    /**
     * 新增【请填写功能名称】
     *
     * @param tbEmployee 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertTbEmployee(TbEmployee tbEmployee) {
        tbEmployee.setCreateDate(new Date());
        return tbEmployeeMapper.insert(tbEmployee);
    }

    /**
     * 修改【请填写功能名称】
     *
     * @param tbEmployee 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateTbEmployee(TbEmployee tbEmployee) {
        return tbEmployeeMapper.updateById(tbEmployee);
    }

    /**
     * 批量删除【请填写功能名称】
     *
     * @param ids 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteTbEmployeeByIds(Long[] ids) {
        return tbEmployeeMapper.deleteBatchIds(Arrays.stream(ids).collect(Collectors.toList()));
    }

    /**
     * 删除【请填写功能名称】信息
     *
     * @param id 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteTbEmployeeById(Long id) {
        return tbEmployeeMapper.deleteById(id);
    }
}
